package gttp.nspa.client.adm;

import gttp.nspa.client.adm.ui.NsShell;

import java.util.logging.Level;
import java.util.logging.Logger;

import com.google.gwt.activity.shared.ActivityManager;
import com.google.gwt.core.client.GWT;
import com.google.gwt.place.shared.PlaceHistoryHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.inject.Inject;
import com.sencha.gxt.widget.core.client.container.Viewport;

public class NsApp {

    static final Logger         log = Logger.getLogger(NsApp.class.getName());

    @Inject
    private ActivityManager     actManager;

    @Inject
    private NsShell             shell;

    @Inject
    private PlaceHistoryHandler historyHandler;

    public void run() {
        init();
    }

    void init() {
        GWT.setUncaughtExceptionHandler(new GWT.UncaughtExceptionHandler() {

            public void onUncaughtException(Throwable e) {
                Window.alert("Error: " + e.getMessage());
                log.log(Level.SEVERE, e.getMessage(), e);
                e.printStackTrace();
            }
        });

        actManager.setDisplay(shell);

        Viewport vp = new Viewport();
        vp.setWidget(shell);
        RootPanel.get().add(vp);

        // Goes to place represented on URL or default place
        historyHandler.handleCurrentHistory();
    }

}
